/**
 * Created by Celebration-Grey on 2017/4/9.
 */

weibo.bowen = {};
weibo.bowen.bowenLi = function (bowenInfo, userInfo, repostInfo) {
    var author_id = userInfo['user_id'];
    var author_nickname = userInfo['user_nickname'];
    var author_head_img = userInfo['user_head_img'];
    var bid = bowenInfo['bowen_id'];
    var content = bowenInfo['bowen_content'];
    var repost_id = bowenInfo['bowen_repost_id'];
    var is_repost = (repost_id == null) ? 0 : 1;
    var comment_count = (bowenInfo['bowen_comment_count'] == 0) ? '评论' : bowenInfo['bowen_comment_count'];
    var like_count = (bowenInfo['bowen_like_count'] == 0) ? '赞' : bowenInfo['bowen_like_count'];
    var repost_count = (bowenInfo['bowen_repost_count'] == 0) ? '转发' : bowenInfo['bowen_repost_count'];
    var img_count = parseInt(bowenInfo['bowen_img_count']);
    var img_urls = bowenInfo['bowen_img_urls'];
    var posttime = bowenInfo['bowen_posttime'];
    posttime = weibo.bowen.dateTimeStamp(posttime);
    posttime = weibo.bowen.dateDiff(posttime);
    var post_device = bowenInfo['bowen_post_device'];
    var dom_string = '<div class="WB_cardwrap WB_feed_type S_bg2 bowen-box"bowen-id=""author-id=""><div class="WB_feed_detail clearfix"><div class="WB_screen W_fr"><div class="screen_box"><a href="javascript:void(0);"><i class="W_ficon ficon_arrow_down S_ficon glyphicon glyphicon-menu-down"></i></a><div class="layer_menu_list"style="display:none; position: absolute; z-index: 999;"><ul><li><a href="javascript:void(0);"title="">帮上头条</a></li><li><a href="javascript:void(0);"title="">屏蔽这条微博</a></li><li><a href="javascript:void(0);"title="">屏蔽这个博主</a></li><li><a href="javascript:void(0);"title="">取消关注</a></li><li><a href="javascript:void(0);">举报</a></li></ul><ul style="display:none;"></ul></div></div></div><div class="WB_face W_fl"><div class="face bowen-user-haed"><a target="_blank"class="W_face_radius"href="javascript:void(0);"title=""><img title=""alt=""width="50"height="50"src="http://tva2.sinaimg.cn/crop.205.263.383.383.50/6ec1bbdejw8f0fhpbponwj20ju0rsn4h.jpg"class="W_face_radius"></a></div></div><div class="WB_detail"><div class="WB_info bowen-info"><a target="_blank"class="W_f14 W_fb S_txt1 bowen-user-nickname"title=""href="javascript:void(0);"></a><a target="_blank"href="javascript:void(0);"style="display:none;"><i title=""class="W_icon icon_approve"style="display:none;"></i></a><a title=""target="_blank"href="javascript:void(0);"style="display:none;"><em class="W_icon icon_member5"></em></a></div><div class="WB_from S_txt2"><a target="_blank"href="javascript:void(0);"title=""class="S_txt2 bowen-posttime"></a>&nbsp;来自&nbsp;<a class="S_txt2"target="_blank"href="javascript:void(0);"rel="nofollow">微博&nbsp;weibo.com</a></div><div class="WB_text W_f14 bowen-content"></div><div class="WB_expand_media_box bowen-media"style="display: none;"></div><div class="WB_media_wrap clearfix bowen-media bowen-media-box"><div class="media_box"></div></div><div class="WB_feed_expand repost-bowen" repost-bowen-id=""><div class="W_arrow_bor W_arrow_bor_t"><i class="S_bg1_br"></i></div><div class="WB_expand S_bg1"><div class="WB_info repost-info"><a target="_blank"class="W_fb S_txt1 repost-user-nickname"href="javascript:void(0);"title="">@博主</a><a target="_blank"href="javascript:void(0);"><i title=""class="W_icon icon_approve"style="display:none"></i></a></div><div class="WB_text repost-content"><a target="_blank"class="a_topic"href="javascript:void(0);">#话题#</a></div><div class="WB_expand_media_box repost-media"style="display: none;"></div><div class="WB_media_wrap clearfix repost-media repost-media-box"><div class="media_box"></div></div><div class="WB_func clearfix"><div class="WB_handle W_fr"><ul class="clearfix"><li><span class="line S_line1"><a class="S_txt2"target="_blank"href="javascript:void(0);"><span><em class="W_ficon ficon_forward S_ficon glyphicon glyphicon-retweet"></em><em class="repost-retweet-count">65</em></span></a></span></li><li><span class="line S_line1"><a class="S_txt2"target="_blank"href="javascript:void(0);"><span><em class="W_ficon ficon_repeat S_ficon glyphicon glyphicon-comment"></em><em class="repost-comment-count">21</em></span></a></span></li><li><span class="line S_line1"><a class="S_txt2"href="javascript:void(0);"title=""><span><em class="W_ficon ficon_praised S_txt2 glyphicon glyphicon-thumbs-up"></em><em class="repost-like-count">199</em></span></a></span></li></ul></div><div class="WB_from S_txt2"><a class="S_txt2 repost-posttime"target="_blank"href="javascript:void(0);"title=""></a>来自<a class="S_txt2 repost-device"target="_blank"href="javascript:void(0);"rel="nofollow">iPhone 7 Plus</a></div></div></div></div></div></div><div class="WB_feed_handle"><div class="WB_handle"><ul class="WB_row_line WB_row_r4 clearfix S_line2"><li><a class="S_txt2 star-bowen-action"href="javascript:void(0);"><span class="pos"><span class="line S_line1"><span><em class="W_ficon ficon_favorite S_ficon glyphicon glyphicon-star-empty"></em><em class="bowen-star">收藏</em></span></span></span></a></li><li><a class="S_txt2 retweet-bowen-action"href="javascript:void(0);"><span class="pos"><span class="line S_line1"><span><em class="W_ficon ficon_forward S_ficon glyphicon glyphicon-retweet"></em><em class="bowen-retweet-count">54</em></span></span></span></a></li><li><a class="S_txt2 comment-bowen-action"href="javascript:void(0);"><span class="pos"><span class="line S_line1"><span><em class="W_ficon ficon_repeat S_ficon glyphicon glyphicon-comment"></em><em class="bowen-comment-count">67</em></span></span></span></a><span class="arrow"style="display: none;"><span class="W_arrow_bor W_arrow_bor_t"><i class="S_line1"></i><em class="S_bg1_br"></em></span></span></li><li><a href="javascript:void(0);"class="S_txt2 like-bowen-action"title=""><span class="pos"><span class="line S_line1"><span class=""><em class="W_ficon ficon_praised S_txt2 glyphicon glyphicon-thumbs-up"></em><em class="bowen-like-count">958</em></span></span></span></a></li></ul></div></div><div class="WB_feed_repeat S_bg1 bowen-comment"style="display:none;"></div></div>';
    var $dom = $(dom_string);
    $dom.attr('id', 'bowen_' + bid);
    $dom.attr('bowen-id', bid);
    $dom.attr('author-id', author_id);
    $dom.find('.bowen-user-haed a').attr('title', author_nickname);
    author_nickname = HtmlUtil.htmlEncodeByRegExp(author_nickname);
    $dom.find('.bowen-user-nickname').html(author_nickname);
    $dom.find('.bowen-user-haed img').attr('src', author_head_img).attr('title', author_nickname).attr('alt', author_nickname);
    content = HtmlUtil.htmlEncodeByRegExp(content);
    content = weibo.emotion.handle(content);
    $dom.find('.bowen-content').html(content);
    $dom.find('.bowen-retweet-count').html(repost_count);
    $dom.find('.bowen-comment-count').html(comment_count);
    $dom.find('.bowen-like-count').html(like_count);
    $dom.find('.bowen-posttime').html(posttime);
    if (img_count <= 0) {
        $dom.find('.bowen-media').remove();
    } else {
        var imgs = img_urls.split(';');
        $dom.find('.repost-media .media_box').append(weibo.bowen.media(imgs));
    }
    if (is_repost) {
        var repost_bowen = repostInfo['bowen'];
        var repost_author = repostInfo['author'];
        var re_author_id = repost_author['user_id'];
        var re_author_nickname = repost_author['user_nickname'];
        var re_bowen_id = repost_bowen['bowen_id'];
        var re_bowen_content = repost_bowen['bowen_content'];
        var re_bowen_img_count = parseInt(repost_bowen['bowen_img_count']);
        var re_bowen_img_urls = repost_bowen['bowen_img_urls'];
        var re_bowen_posttime = repost_bowen['bowen_posttime'];
        var re_bowen_post_device = repost_bowen['bowen_post_device'];
        var re_comment_count = repost_bowen['bowen_comment_count'];
        var re_repost_count = repost_bowen['bowen_repost_count'];
        var re_like_count = repost_bowen['bowen_like_count'];
        $dom.find('.repost-bowen').attr('repost-bowen-id', re_bowen_id).attr('repost-author-id', re_author_id);
        $dom.find('.repost-user-nickname').attr('title', re_author_nickname).html('@' + re_author_nickname);
        re_bowen_content = HtmlUtil.htmlEncodeByRegExp(re_bowen_content);
        re_bowen_content = weibo.emotion.handle(re_bowen_content);
        $dom.find('.repost-content').html(re_bowen_content);
        $dom.find('.repost-retweet-count').html(re_repost_count);
        $dom.find('.repost-comment-count').html(re_comment_count);
        $dom.find('.repost-like-count').html(re_like_count);
        $dom.find('.repost-posttime').html(re_bowen_posttime);
        if (re_bowen_img_count <= 0) {
            $dom.find('.repost-media').remove();
        }
        else {
            var img_array = re_bowen_img_urls.split(';');
            $dom.find('.repost-media .media_box').append(weibo.bowen.media(img_array));
            // console.log(img_array);
        }
    } else {
        $dom.find('.repost-bowen').remove();
    }
    $dom.find('.comment-bowen-action').click(function () {
        $(this).addClass('btn_disable');
        var $repeat = weibo.bowen.repeat(bid);
        weibo.bowen.getComments($repeat, bid);
        $dom.append($repeat);
    });
    $dom.find('.like-bowen-action').click(function () {
        $(this).addClass('btn_disable');
        weibo.bowen.likeBowen(bid);
    });
    $dom.find('.screen_box').click(function () {
        $(this).find('.layer_menu_list').toggle();
    });
    $dom.find('.WB_face, .bowen-user-nickname').mouseenter(function () {
        // weibo.bowen.getAuthorInfo($(this), author_id);
        var $this = $(this);
        var timee = setTimeout(function () {
            weibo.bowen.getAuthorInfo($this, author_id);
        },400);
        $(this).mouseleave(function () {
            clearTimeout(timee);
        })
    });
    $dom.fadeIn(400);
    return $dom;
};

weibo.bowen.repeat = function (bowen_id) {
    var user_head_img = userInfo['user_head_img'];
    var user_nickname = userInfo['user_nickname'];
    var repeat_string = '<div class="WB_feed_repeat S_bg1"style=""><div class="WB_feed_repeat S_bg1 WB_feed_repeat_v3"><div class="WB_repeat S_line1"><div class="WB_feed_publish clearfix"><div class="WB_face W_fl"><img src=""alt=""></div><div class="WB_publish"><div class="p_input"><textarea class="W_input"cols=""rows=""name=""range="0&amp;0"style="margin: 0px; padding: 5px 2px 0px 6px; border-style: solid; border-width: 1px; font-size: 12px; word-wrap: break-word; line-height: 18px; overflow: hidden; outline: none; height: 23px;"></textarea></div><div class="p_opt clearfix"><div class="btn W_fr"><a class="W_btn_a W_btn_a_disable reply-btn"href="javascript:void(0);">评论</a></div><div class="opt clearfix"><span class="ico"><a href="javascript:void(0);"title="表情"alt=""><i class="W_ficon ficon_face glyphicon glyphicon-gift"></i></a><a href="javascript:void(0);"style="cursor:default;"title=""><i class="W_ficon ficon_image S_ficon_dis glyphicon glyphicon-picture"></i></a></span><ul class="ipt"><li><label for=""class="W_label"><input id=""class="W_checkbox"type="checkbox"name="forward"><span>同时转发到我的微博</span></label></li><li><label for=""class="W_label"><input id=""class="W_checkbox"type="checkbox"name="isroot"><span>同时评论给原文作者</span></label></li></ul></div></div></div></div><div class="repeat_list"><div class="tab_feed_a clearfix S_line1"><div class="tab"><ul class="clearfix"><li><span class="line S_line1"><a href="javascript:void(0);"class="S_txt1 curr">按热度</a></span></li><li><span class="line S_line1"><a href="javascript:void(0);"class="S_txt1">按时间</a></span></li></ul></div></div><div class="list_box"><div class="list_ul comment-ul"></div></div></div></div></div></div>';
    var $repeat = $(repeat_string);
    $repeat.find('.WB_face img').attr('src', user_head_img).attr('alt', user_nickname);
    $repeat.find('textarea.W_input').keyup(function () {
        var content = $(this).val();
        if (content) {
            $(this).parents('.WB_feed_publish').find('.reply-btn').removeClass('W_btn_a_disable');
        } else {
            $(this).parents('.WB_feed_publish').find('.reply-btn').addClass('W_btn_a_disable');
        }
    });
    $repeat.find('.reply-btn').click(function () {
        $(this).addClass('W_btn_a_disable');
        var content = $(this).parents('.WB_feed_publish').find('textarea.W_input').val();
        weibo.bowen.comBowen(bowen_id, content);
    });
    $repeat.find('.glyphicon-gift').click(function () {
        $(this).addClass('btn_disable');
        var x = $(this).offset().top;
        var y = $(this).offset().left;
        var $box = weibo.emotion.emotionBox($(this));
        $box.css('top', x + 20).css('left', y - 17);
        $('body').append($box);
    });
    $repeat.fadeIn(400);
    return $repeat;
};

weibo.bowen.commentLi = function (commentInfo) {
    var c_id = commentInfo['comment']['comment_id'];
    var c_content = commentInfo['comment']['comment_content'];
    var c_like_count = commentInfo['comment']['comment_like_count'];
    c_like_count = c_like_count == 0 ? '赞' : c_like_count;
    var c_reply_count = commentInfo['comment']['comment_reply_count'];
    var c_img_count = commentInfo['comment']['comment_img_count'];
    var c_img_url = commentInfo['comment']['comment_img_url'];
    var c_datetime = commentInfo['comment']['comment_datetime'];
    c_datetime = weibo.bowen.dateTimeStamp(c_datetime);
    c_datetime = weibo.bowen.dateDiff(c_datetime);
    var c_author_id = commentInfo['author']['user_id'];
    var c_replys = commentInfo['replys'];
    var c_author_nickname = commentInfo['author']['user_nickname'];
    var c_author_haed_img = commentInfo['author']['user_head_img'];
    var c_author_level = commentInfo['author']['user_level'];
    var comment_string = '<div comment-id=""class="list_li S_line1 clearfix comment-box"><div class="WB_face W_fl comment-user-head"><a target="_blank"href="javascript:void(0);"><img alt=""src=""></a></div><div class="list_con"><div class="WB_text comment-content"></div><div class="WB_expand_media_box comment-media"style="display: none;"></div><div class="WB_func clearfix"><div class="WB_handle W_fr"><ul class="clearfix"><li class="hover"><span class="line S_line1"><a class="S_txt1"href="javascript:void(0);">举报</a></span></li><li class="hover"><span class="line S_line1"><a class="S_txt1"href="javascript:void(0);">屏蔽</a></span></li><li><span class="line S_line1"><a href="javascript:void(0);"class="S_txt1 comment-reply-action"title="">回复</a></span><span class="arrow"><span class="W_arrow_bor W_arrow_bor_t"><i class="S_bg2_br"></i></span></span></li><li><span class="line S_line1"><a href="javascript:void(0);"class="S_txt1 comment-like-action"title="赞"><span class=""><em class="W_ficon ficon_praised S_txt2 glyphicon glyphicon-thumbs-up"></em><em class="comment-like-count">14</em></span></a></span></li></ul></div><div class="WB_from S_txt2 comment-datetime">4月8日11:41</div></div><div class="list_box_in S_bg3"><div class="list_ul reply-ul"><div class="list_li_v2 more-reply"style="display: none;"><div class="WB_text"><a target="_blank"href="javascript:void(0);"></a></div></div></div></div></div></div>';
    var $dom = $(comment_string);
    $dom.attr('id', 'comment_' + c_id);
    $dom.attr('comment-id', c_id);
    c_author_nickname = HtmlUtil.htmlEncodeByRegExp(c_author_nickname);
    $dom.find('.comment-user-head a').attr('title', c_author_nickname);
    $dom.find('.comment-user-head img').attr('alt', c_author_nickname).attr('src', c_author_haed_img);
    c_content = HtmlUtil.htmlEncodeByRegExp(c_content);
    var comment_content = weibo.emotion.handle(c_content);
    var text = '<a class="comment-author-nickname" target="_blank" href="javascript:void(0);">' + c_author_nickname + '</a>：' + comment_content;
    $dom.find('.comment-content').html(text);
    $dom.find('.comment-like-count').html(c_like_count);
    $dom.find('.comment-datetime').html(c_datetime);
    if (c_replys != null && c_replys.length > 0) {
        for (var i = 0; i < c_replys.length; i++) {
            $dom.find('.reply-ul').append(weibo.bowen.replyLi(c_replys[i]));
        }
    }
    $dom.find('.reply-ul').append('<div class="between_line S_bg1"></div>');
    $dom.find('.comment-reply-action').click(function () {
        // console.log(c_id);
        $(this).addClass('btn_disable');
        $(this).parents('.WB_func').append(weibo.bowen.replyInput(c_id, c_author_nickname));
    });
    $dom.find('.comment-like-action').click(function () {
        $(this).addClass('btn_disable');
        weibo.bowen.likeComment(c_id);
    });
    $dom.find('.WB_face, .comment-author-nickname').mouseenter(function () {
        var $this = $(this);
        var timee = setTimeout(function () {
            weibo.bowen.getAuthorInfo($this, c_author_id);
        },400);
        $(this).mouseleave(function () {
            clearTimeout(timee);
        })
    });
    $dom.fadeIn(400);
    return $dom;
};

weibo.bowen.replyLi = function (replyInfo) {
    var r_id = replyInfo['reply']['reply_id'];
    var r_content = replyInfo['reply']['reply_content'];
    var r_like_count = replyInfo['reply']['reply_like_count'];
    r_like_count = r_like_count == 0 ? '赞' : r_like_count;
    var r_datetime = replyInfo['reply']['reply_datetime'];
    r_datetime = weibo.bowen.dateTimeStamp(r_datetime);
    r_datetime = weibo.bowen.dateDiff(r_datetime);
    var r_author_id = replyInfo['author']['user_id'];
    var r_author_nickname = replyInfo['author']['user_nickname'];
    var r_author_level = replyInfo['author']['user_level'];
    var c_id = replyInfo['reply']['reply_comment_id'];
    var reply_string = '<div reply-id=""class="list_li S_line1 clearfix reply-box"><div class="list_con"><div class="WB_text reply-content"></div><div class="WB_expand_media_box reply-media"style="display: none;"></div><div class="WB_func clearfix"><div class="WB_handle W_fr"><ul class="clearfix"><li class="hover"><span class="line S_line1"><a class="S_txt1"href="javascript:void(0);">举报</a></span></li><li class="hover"><span class="line S_line1"><a class="S_txt1"href="javascript:void(0);">屏蔽</a></span></li><li class="hover"><span class="line S_line1"><a class="S_txt1"href="javascript:void(0);">查看对话</a></span></li><li><span class="line S_line1"><a href="javascript:void(0);"class="S_txt1 reply-reply-action"title="">回复</a></span><span class="arrow"><span class="W_arrow_bor W_arrow_bor_t"><i class="S_bg2_br"></i></span></span></li><li><span class="line S_line1"><a href="javascript:void(0);"class="S_txt1 reply-like-action"title="赞"><span class=""><em class="W_ficon ficon_praised S_txt2 glyphicon glyphicon-thumbs-up"></em><em class="reply-like-count">2</em></span></a></span></li></ul></div><div class="WB_from S_txt2 reply-datetime"></div></div></div></div>';
    var $dom = $(reply_string);
    $dom.attr('id', 'reply_' + r_id);
    $dom.attr('reply-id', r_id);
    r_content = HtmlUtil.htmlEncodeByRegExp(r_content);
    var reply_content = weibo.emotion.handle(r_content);
    $dom.find('.reply-content').html('<a class="reply-author-nickname" target="_blank" href="javascript:void(0);">' + r_author_nickname + '</a>：' + reply_content);
    $dom.find('.reply-like-count').html(r_like_count);
    $dom.find('.reply-datetime').html(r_datetime);
    $dom.find('.reply-reply-action').click(function () {
        $(this).addClass('btn_disable');
        $(this).parents('.WB_func').append(weibo.bowen.replyInput(c_id, r_author_nickname));
    });
    $dom.find('.reply-like-action').click(function () {
        $(this).addClass('btn_disable');
        weibo.bowen.likeReply(r_id);
    });
    $dom.find('.reply-author-nickname').mouseenter(function () {
        var $this = $(this);
        var timee = setTimeout(function () {
            weibo.bowen.getAuthorInfo($this, r_author_id);
        },400);
        $(this).mouseleave(function () {
            clearTimeout(timee);
        })
    });
    $dom.fadeIn(400);
    return $dom;
};

weibo.bowen.replyInput = function (comment_id, user_nickname) {
    var reply_input_string = '<div class="WB_repeat_in S_bg2"><div class="WB_feed_publish clearfix"><div class="WB_publish"><div class="p_input"><textarea class="W_input reply-content"></textarea><input type="hidden"class="reply-comment-id"value=""/></div><div class="p_opt clearfix"><div class="btn W_fr"><a class="W_btn_a W_btn_a_disable reply-btn">评论</a></div><div class="opt clearfix"><span class="ico"><a><i class="W_ficon ficon_face glyphicon glyphicon-gift"></i></a></span><span class="ico"><a style="cursor:default;"title="非会员暂不支持网页版评论发图功能"><i class="W_ficon ficon_image S_ficon_dis glyphicon glyphicon-picture"></i></a></span><ul class="ipt"><li><label class="W_label"><input name=""type="checkbox"value=""class="W_checkbox"><span>同时转发到我的微博</span></label></li></ul></div></div></div></div></div>';
    var $dom = $(reply_input_string);
    $dom.find('textarea.W_input').val('回复@' + user_nickname + ':');
    $dom.find('input.reply-comment-id').val(comment_id);
    $dom.find('textarea.W_input').keyup(function () {
        var pattern = /回复@.*?:$/g;
        var content = $(this).val();
        if (content != "" && !pattern.test(content)) {
            $(this).parents('.WB_repeat_in').find('.reply-btn').removeClass('W_btn_a_disable');
        } else {
            $(this).parents('.WB_repeat_in').find('.reply-btn').addClass('W_btn_a_disable');
        }
    });
    $dom.find('.reply-btn').click(function () {
        var content = $(this).parents('.WB_feed_publish').find('.reply-content').val();
        $(this).addClass('W_btn_a_disable');
        weibo.bowen.repComment(comment_id, content);
    });
    $dom.fadeIn(400);
    return $dom;
};

weibo.bowen.userCard = function (authorInfo, $hover) {
    var card_img = authorInfo['user_card_img'];
    var head_img = authorInfo['user_head_img'];
    var nickname = authorInfo['user_nickname'];
    var followed = authorInfo['user_followed_count'];
    var followings = authorInfo['user_following_count'];
    var bowen = authorInfo['user_bowen_count'];
    var info = authorInfo['user_info'];
    var sex = authorInfo['user_sex'];
    var domstring = '<div class="W_layer W_layer_pop"id=""style=""><div class="content"><div class="layer_personcard"><div class="layer_personcard"><div style="background-image:url()"class="nc_head"><div class="pic_box"><a href="javascript:void(0);"target="_blank"><img width="50"height="50"src=""title=""class="W_face_radius"></a></div><div class="mask"><div class="name"><a class="W_f14"target="_blank"href="javascript:void(0);"title=""></a><em class="W_icon author-sex"title="女"></em></div><div class="intro W_autocut"><span title="半次元人气绘师"></span></div></div></div><div class="nc_content"><div class="c_count"><span class="c_follow W_fb"><a target="_blank"href="javascript:void(0);">关注<em class="num  W_fb em-following"></em></a></span><span class="c_fans W_fb"><a target="_blank"href="javascript:void(0);">粉丝<em class="num W_fb em-followed"></em></a></span><span class="c_weibo W_fb"><a target="_blank"href="javascript:void(0);">微博<em class="num W_fb em-bowen"></em></a></span></div><div class="user_info"><ul class="info_ul clearfix"><li class="info_li"><a class="interval W_autocut S_txt1"target="_blank"href="javascript:void(0);"title="辽宁">辽宁</a></li><li class="info_li"><em class="S_txt2">毕业于</em><a target="_blank"class="detail W_autocut S_txt1"href="javascript:void(0);"title="鲁迅美术学院">鲁迅美术学院</a></li><li class="info_li"><em class="S_txt2">就职于</em><a target="_blank"class="detail W_autocut S_txt1"href="javascript:void(0);"title="家里蹲">家里蹲</a></li></ul></div><div class="c_btnbox"><a href="javascript:void(0);"class="W_btn_b"><em class="W_ficon ficon_right glyphicon glyphicon-ok"></em>已关注<em class="W_ficon ficon_arrow_down_lite glyphicon glyphicon-triangle-bottom"></em></a><a class="W_btn_b"href="javascript:void(0);">私信</a><a href="javascript:void(0);"class="W_btn_b W_btn_pf_menu"><em class="W_ficon ficon_menu S_ficon glyphicon glyphicon-align-justify"></em></a></div></div></div></div></div></div>';
    var $dom = $(domstring);
    $dom.find('.nc_head').css('background-image', 'url(' + card_img + ')');
    $dom.find('img.W_face_radius').attr('src', head_img).attr('title', nickname);
    $dom.find('.em-following').html(followings);
    $dom.find('.em-followed').html(followed);
    $dom.find('.em-bowen').html(bowen);
    nickname = HtmlUtil.htmlEncodeByRegExp(nickname);
    $dom.find('.name .W_f14').html(nickname).attr('title', nickname);
    info = HtmlUtil.htmlEncodeByRegExp(info);
    $dom.find('.W_autocut span')[0].innerHTML = '简介：' + info;
    if(sex == 0){
        $dom.find('.author-sex').addClass('male').attr('title','男');
    }
    else{
        $dom.find('.author-sex').addClass('female').attr('title','女');
    }
    var pos = $hover.offset();
    $dom.css('top', pos.top - 225).css('left', pos.left - 20);
    var now = new Date().getTime();
    $dom.attr('id', 'layer_' + now);
    weibo.bowen.hoverShow($hover, $dom);
    $dom.fadeIn(400);
    return $dom;
};

weibo.bowen.hoverShow = function ($face, $card) {
    var timer;
    var timer1;
    $face.unbind('mouseleave');
    $face.mouseleave(function () {
        timer = setTimeout(function () {
            $card.remove();
            $face.unbind('mouseenter');
            $face.mouseenter(function () {
                timer1 = setTimeout(function () {
                    weibo.bowen.hoverShow($face, $card);
                    $card.fadeIn(400);
                    $('.W_layer.W_layer_pop').remove();
                    $('body').append($card);
                }, 500);
                $face.mouseleave(function () {
                    clearTimeout(timer1);
                });
            });
        }, 1000);
        $card.unbind('mouseenter');
        $card.mouseenter(function () {
            clearTimeout(timer);
        });
        $face.unbind('mouseenter');
        $face.mouseenter(function () {
            clearTimeout(timer);
        });
    });
    $card.unbind('mouseleave');
    $card.mouseleave(function () {
        timer = setTimeout(function () {
            $card.remove();
            $face.unbind('mouseenter');
            $face.mouseenter(function () {
                timer1 = setTimeout(function () {
                    weibo.bowen.hoverShow($face, $card);
                    $card.fadeIn(400);
                    $('.W_layer.W_layer_pop').remove();
                    $('body').append($card);
                }, 500);
                $face.mouseleave(function () {
                    clearTimeout(timer1);
                });
            });
        }, 1000);
        $card.unbind('mouseenter');
        $card.mouseenter(function () {
            clearTimeout(timer);
        });
        $face.unbind('mouseenter');
        $face.mouseenter(function () {
            clearTimeout(timer);
        });
    });
};

weibo.bowen.media = function (imgs) {
    var lis = '';
    for (var i = 0; i < imgs.length; i++) {
        lis += '<li class="WB_pic li_' + (i + 1) + ' S_bg1 S_line2 bigcursor"><img src="' + imgs[i] + '"></li>';
    }
    var $lis = $(lis);
    var $ul = $('<ul class="WB_media_a WB_media_a_mn WB_media_a_m' + imgs.length + ' clearfix"></ul>');
    if (imgs.length == 1) {
        $ul.removeClass('WB_media_a_mn');
    }
    $ul.append($lis);
    return $ul;
};

weibo.bowen.getComments = function ($repeat, bowenId) {
    $.ajax({
        type: 'GET',
        url: host + 'weibo_getComments',
        data: {
            bowen_id: bowenId
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (data) {
            if (data.status == 200) {
                var commtents = data.data['comments'];
                if (commtents != null) {
                    for (var i = 0; i < commtents.length; i++) {
                        $repeat.find('.comment-ul').eq(0).append(weibo.bowen.commentLi(commtents[i]));
                    }
                }
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    })
};

weibo.bowen.comBowen = function (bowenId, content) {
    $.ajax({
        type: 'POST',
        url: host + 'weibo_comBowen',
        data: {
            comment_bowen_id: bowenId,
            comment_content: content
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (data) {
            if (data.status == 200) {
                var comment = data.data[0];
                var $parent = $('#bowen_' + bowenId);
                $parent.find('.comment-ul').eq(0).prepend(weibo.bowen.commentLi(comment));
                $parent.find('.reply-btn').removeClass('W_btn_a_disable');
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    })
};

weibo.bowen.repComment = function (commentId, content) {
    $.ajax({
        type: 'POST',
        url: host + 'weibo_repComment',
        data: {
            reply_comment_id: commentId,
            reply_content: content
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (data) {
            if (data.status == 200) {
                var reply = data.data[0];
                var $parent = $('#comment_' + commentId);
                $parent.find('.reply-ul').prepend(weibo.bowen.replyLi(reply));
                $parent.find('.btn_disable').removeClass('btn_disable');
                $parent.find('.WB_repeat_in').remove();
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    })
};

weibo.bowen.likeBowen = function (bowenId) {
    $.ajax({
        type: 'GET',
        url: host + 'weibo_likeBowen',
        data: {
            bowen_id: bowenId
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (data) {
            if (data.status == 200) {
                $('#bowen_' + bowenId).find('.bowen-like-count').html(data.data['bowen_like_count']);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    })
};

weibo.bowen.likeComment = function (commentId) {
    $.ajax({
        type: 'GET',
        url: host + 'weibo_likeComment',
        data: {
            comment_id: commentId
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (data) {
            if (data.status == 200) {
                $('#comment_' + commentId).find('.comment-like-count').html(data.data['comment_like_count']);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    })
};

weibo.bowen.likeReply = function (replyId) {
    $.ajax({
        type: 'GET',
        url: host + 'weibo_likeReply',
        data: {
            reply_id: replyId
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (data) {
            if (data.status == 200) {
                $('#reply_' + replyId).find('.reply-like-count').html(data.data['reply_like_count']);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    })
};

weibo.bowen.getAuthorInfo = function ($hover, author_id) {
    $('.W_layer.W_layer_pop').remove();
    $hover.unbind('mouseenter');
    $.ajax({
        type: 'GET',
        url: host + 'weibo_authorInfo',
        data: {
            author_id: author_id
        },
        xhrFields: {
            withCredentials: true
        },
        complete: function (XMLHttpRequest, textStatus) {

        },
        success: function (data) {
            if (data.status == 200) {
                var $card = weibo.bowen.userCard(data.data, $hover);
                $('body').append($card);
            }
            else if (data.status == 304) {

            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        }
    });

};

var HtmlUtil = {
    /*1.用正则表达式实现html转码*/
    htmlEncodeByRegExp: function (str) {
        var s = "";
        if (str.length == 0) return "";
        s = str.replace(/&/g, "&amp;");
        s = s.replace(/</g, "&lt;");
        s = s.replace(/>/g, "&gt;");
        s = s.replace(/ /g, "&nbsp;");
        s = s.replace(/\'/g, "&#39;");
        s = s.replace(/\"/g, "&quot;");
        return s;
    },
    /*2.用正则表达式实现html解码*/
    htmlDecodeByRegExp: function (str) {
        var s = "";
        if (str.length == 0) return "";
        s = str.replace(/&amp;/g, "&");
        s = s.replace(/&lt;/g, "<");
        s = s.replace(/&gt;/g, ">");
        s = s.replace(/&nbsp;/g, " ");
        s = s.replace(/&#39;/g, "\'");
        s = s.replace(/&quot;/g, "\"");
        return s;
    }
};

weibo.bowen.dateDiff = function (dateTimeStamp) {
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - dateTimeStamp;
    if (diffValue < 0) {
        return;
    }
    var monthC = diffValue / month;
    var weekC = diffValue / (7 * day);
    var dayC = diffValue / day;
    var hourC = diffValue / hour;
    var minC = diffValue / minute;
    if (monthC >= 1) {
        result = "" + parseInt(monthC) + "月前";
    }
    else if (weekC >= 1) {
        result = "" + parseInt(weekC) + "周前";
    }
    else if (dayC >= 1) {
        result = "" + parseInt(dayC) + "天前";
    }
    else if (hourC >= 1) {
        result = "" + parseInt(hourC) + "小时前";
    }
    else if (minC >= 1) {
        result = "" + parseInt(minC) + "分钟前";
    } else {
        result = "刚刚";
    }
    return result;
};

weibo.bowen.dateTimeStamp = function (dateStr) {
    return Date.parse(dateStr.replace(/-/gi, "/"));
};